<template>
    <div class="e-form">
        <BillTop @cancel="handleClose"></BillTop>
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <el-form ref="form" :model="formData" label-width="160px" :rules="rules">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="机构：">
                          {{formData.orgName}}
                        </el-form-item>
                        </el-col>
                    <el-col :span="12">
                        <el-form-item label="经办人：">
                        {{formData.operatorName}}
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="12">
                       <el-form-item label="结算日期：" prop="settleDate" v-model="formData.settleDate">
                            <el-date-picker
                                v-model="formData.settleDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                      <el-col :span="12">
                        <el-form-item label="传财务共享：">
                             <span :class="isFontColor ? 'redFont' : 'greenFont'">{{shareLable(formData.isSharing)}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
              <el-row>
            <el-col :span="24">
                       <el-form-item label="备注：" >
                            <el-input placeholder="" v-model="formData.remarks" class="input-with-select" type="textarea"
                            :rows="3"  maxlength='500'>
                            <span>
                                {{formData.remarks}}
                            </span>
                            </el-input>
                        </el-form-item>
                    </el-col>
              </el-row>
            </el-form>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                @click="preserve"
                v-debounce
                >保存</el-button
            >
            <el-button size="small" @click="handleClose"  v-debounce>取消</el-button>
        </div>
    </div>
</template>

<script>
import request from '@/api/settlementManagement/weeklyMaterialSettlement/internalRentTransferSettlement'
import { mapState } from 'vuex'
import { formatDate } from '@/utils/common'
export default {
    data () {
        return {
            checkedBox: false,
            formData: {
                'orgId': '',
                'orgName': '',
                'remarks': '',
                'settleDate': formatDate(new Date(), 'yyyy-MM-dd'), //结算日期,
                'isSharing': 0,
                'operatorId': '',
                'operatorName': ''
            },
            rules: {
                settleDate: [
                    { required: true, message: '请选择结算日期', trigger: 'blur' }
                ],
                remarks: [
                    { max: 500, message: '长度不超过500个字符', trigger: 'blur' }
                ],
            },
            isFontColor: true, //传输财务共享颜色  未传，返回修改 红色   财务共享审核中，已传 绿色
        }
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            shareFrom: state => state.equip.equipData.shareFrom,
        }),
        //传输财务共享
        shareLable () {
            return param=> {
                const state = this.shareFrom
                const obj = state.find(x=>x.value === param)
                return (obj ?  obj.label :  '')
            }
        },
    },
    created () {
        this.getInInfo ()
    },
    components: {
    },
    mounted () {
    },
    methods: {
        //获取默认数据
        getInInfo () {
            const { orgInfo, userName, userId } = this.userInfo
            this.formData.orgId = orgInfo.orgId //机构id
            this.formData.orgName = orgInfo.orgName // 机构名称
            this.formData.operatorId = userId // 经办人Id
            this.formData.operatorName = userName // 经办人名称
        },
        //保存
        preserve () {
            this.$refs.form.validate(valid => {
                if (valid) {
                    this.formData.redState = -1
                    request.addInternalRentTransferData(this.formData).then(res=>{
                        this.clientPop('info', '保存成功!是否进行下一步操作？', ()=>{
                            this.$router.push({
                                path: '/internalRentTransferSettlementEdit',
                                query: {
                                    billid: res,
                                    name: 'changeDetail'
                                }
                            })
                        },
                        null,
                        this.handleClose
                        )
                    })
                } else {
                    return false
                }
            })
        },
        //取消
        handleClose () {
            this.$router.replace('/internalRentTransferSettlementList')
        },
    },
    watch: {
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
</style>
